package br.com.sisgerenciamento.filtro;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.sisgerenciamento.util.Constants;

public class FiltroSeguranca implements Filter {
	

	public void destroy() {
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filter) throws IOException, ServletException {

		HttpServletRequest httpRequest = (HttpServletRequest) request;
		String codUsuario = (String) httpRequest.getSession().getAttribute(Constants.CODIGO_USUARIO);
		if (codUsuario == null || "".equals(codUsuario))
			((HttpServletResponse) response).sendRedirect("../publico/loginAction.do?action=login");
		
		filter.doFilter(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
	}

}
